new Vue({
	el: "body",
	data: {
		name: "",
		pwd: "",
		reged: false,
		unpwd: false,
		loading: true
	},
	methods: {
		log: function() {
			this.reged=false;
		    this.unpwd= false;
			var name = this.name;
			if(!(/^1[34578]\d{9}$/.test(name))) {
				alert("手机号码有误，请重填");
			} else {
				var pwd = this.pwd;
				this.login(name, pwd);
			}
		},
		login: function(name, pwd) {
			//登录
			var n = name;
			var p = pwd;
			var _this = this;
			AV.User.logIn(name, pwd).then(function(loginedUser) {
				console.log(loginedUser);
				history.go(-1); //登录成功
			}, function(error) {
				console.log(error.code)
				if(error.code == 211) { //未注册
					_this.reg(n, p);
				}
				//封禅大典多多多多多多多多多多多多多多多多多多多多多多多多多多多多多
				if(error.code == 210) {
					//密码错误
					_this.unpwd = true;
				}
			});
		},
		reg: function(name, pwd) {
			var _this=this;
			//注册
			// 新建 AVUser 对象实例
			var user = new AV.User();
			// 设置用户名
			user.setUsername(name);
			// 设置密码
			user.setPassword(pwd);
			user.signUp().then(function(loginedUser) {
				console.log("success");
				this.login(name, pwd)
			}, function(error) {
				console.log(error);
				//的点点滴滴多多多多多多多多多多多多多多多多多多多多多多多多多多多多多
				if(error.code == 201) { //已注册
					_this.reged = true;
				}
			});
		}
	},
	created: function() {
		init();
	}
})